// exports.AL_Framework_Lobby_Buried_Point = void 0;
// var $lobbyConfig = require("./AL_Framework_Lobby_Config");
// var n = (function () {
//     function e() {
//         this.msg = null;
//         this.bundle_shijian = 0;
//         this.startTime = 0;
//         this.submit_time = 0;
//         this.event_submit_times = 60;
//         this.is_BuriedPoint = !1;
//         this.bundle_state_string = ["全量下载", "进入游戏", "退出子游戏", "全量下载成功", "热更下载", "热更下载成功"];
//     }
//     e.getInstance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     e.prototype.chushihua_bundle_shijian = function () {
//         this.bundle_shijian = Date.parse(Date());
//     };
//     e.prototype.huoquBundleShijian = function () {
//         return this.bundle_shijian;
//     };
//     e.prototype.huoquLikaishijian = function (e) {
//         var t = Date.parse(Date());
//         e.time = (t - this.bundle_shijian) / 1e3;
//         var o = localStorage.getItem($lobbyConfig.AL_Framework_Lobby_Config.Buried_Point_Time_Key);
//         if (o) {
//             localStorage.removeItem($lobbyConfig.AL_Framework_Lobby_Config.Buried_Point_Time_Key);
//             e.time += JSON.parse(o).time;
//         }
//         e.time = e.time > 18e4 || e.time < 0 ? -1 : e.time;
//     };
//     e.prototype.chushihua_shijian_tijiao_shijian = function () {
//         if (ailin_sdk_manager.instance.jianchaZaixianShujuShifouKaiqi) {
//             var e = ailin_sdk_manager.instance.jianchaZaixianShujuShifouKaiqi("event_submit_times");
//             console.log("大厅埋点接口请求状态:" + e);
//             e == $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.ZERO
//                 ? (this.event_submit_times = 60)
//                 : e == $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.ONE
//                 ? (this.event_submit_times = 120)
//                 : e == $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.TWO
//                 ? (this.event_submit_times = 0)
//                 : e == $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.THREE
//                 ? (this.event_submit_times = -1)
//                 : (this.event_submit_times = e >= 300 ? 300 : e < 0 ? 5 : e);
//             console.log("大厅埋点接口请求时间:" + this.event_submit_times);
//         }
//     };
//     e.prototype.fasong_http_qingqiu_kuozhan = function (e, t) {
//         if (void 0 === t) {
//             t = $lobbyConfig.AL_Framework_Lobby_Config.BUNDLE_STATE.CLICK;
//         }
//         var o = $lobbyConfig.AL_Framework_Lobby_Config.BUNDLE_STATE;
//         if (e) {
//             if (t == o.EXIT) {
//                 this.is_BuriedPoint = !1;
//                 this.startTime = 0;
//                 this.msg = null;
//                 this.huoquLikaishijian(e);
//             }
//             var n = {
//                 bundleId: e.id || e.bundleId,
//                 type: t == o.COMPENSATE_EXIT ? o.EXIT : t,
//                 onlineTime: null == e.time || null == e.time ? null : e.time,
//                 version: e.version,
//                 device: window.device,
//                 createdAt: Date.parse(Date())
//             };
//             if (t == o.START) {
//                 this.chushihua_bundle_shijian();
//                 this.is_BuriedPoint = !0;
//                 this.msg = e;
//                 this.msg.time = 0;
//                 this.msg.node = null;
//             }
//             if (0 == this.event_submit_times) {
//                 ailin_sdk_manager.instance.setDataForHttpPust($lobbyConfig.AL_Framework_Lobby_Config.httpUrlEvent, JSON.stringify(n));
//             } else {
//                 if (this.event_submit_times > 0) {
//                     var a = localStorage.getItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key);
//                     var s = [];
//                     if (a) {
//                         try {
//                             s = JSON.parse(a);
//                         } catch (e) {
//                             s = [];
//                         }
//                     }
//                     s.push(n);
//                     !this.submit_time || (Date.parse(Date()) - this.submit_time) / 1e3 >= this.event_submit_times
//                         ? ((this.submit_time = Date.parse(Date())),
//                           localStorage.removeItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key),
//                           ailin_sdk_manager.instance.setDataForHttpPust(
//                               $lobbyConfig.AL_Framework_Lobby_Config.httpUrlBatchEvent,
//                               JSON.stringify(s)
//                           ))
//                         : localStorage.setItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key, JSON.stringify(s));
//                     ailin_sdk_manager.addBossTitle(
//                         "数据埋点：" +
//                             e.bundle +
//                             "---id:" +
//                             e.id +
//                             "----" +
//                             this.bundle_state_string[t - 1] +
//                             (2 == t ? "----time:" + Date() : 3 == t ? "----游戏时间:" + e.time : "")
//                     );
//                 }
//             }
//         }
//     };
//     e._instance = null;
//     return e;
// })();
// exports.AL_Framework_Lobby_Buried_Point = n;


// 导出LobbyBuriedPoint
exports.AL_Framework_Lobby_Buried_Point = void 0;

// 引入LobbyConfig模块
const $lobbyConfig = require("./AL_Framework_Lobby_Config");

/**
 * @class AL_Framework_Lobby_Buried_Point
 * @description 用于管理大厅埋点的单例类
 */
class AL_Framework_Lobby_Buried_Point {
    constructor() {
        this.msg = null;
        this.bundle_shijian = 0;
        this.startTime = 0;
        this.submit_time = 0;
        this.event_submit_times = 60;
        this.is_BuriedPoint = false;
        this.bundle_state_string = ["全量下载", "进入游戏", "退出子游戏", "全量下载成功", "热更下载", "热更下载成功"];
    }

    /**
     * @description 获取单例实例
     * @returns {AL_Framework_Lobby_Buried_Point} 单例实例
     */
    static getInstance() {
        if (!this._instance) {
            this._instance = new AL_Framework_Lobby_Buried_Point();
        }
        return this._instance;
    }

    /**
     * @description 初始化bundle时间
     */
    chushihua_bundle_shijian() {
        this.bundle_shijian = Date.parse(new Date());
    }

    /**
     * @description 获取bundle时间
     * @returns {number} bundle时间
     */
    huoquBundleShijian() {
        return this.bundle_shijian;
    }

    /**
     * @description 获取离开时间并保存到传入对象中
     * @param {Object} event 事件对象
     */
    huoquLikaishijian(event) {
        const currentTime = Date.parse(new Date());
        event.time = (currentTime - this.bundle_shijian) / 1000;
        const storedTime = localStorage.getItem($lobbyConfig.AL_Framework_Lobby_Config.Buried_Point_Time_Key);
        if (storedTime) {
            localStorage.removeItem($lobbyConfig.AL_Framework_Lobby_Config.Buried_Point_Time_Key);
            event.time += JSON.parse(storedTime).time;
        }
        event.time = event.time > 180000 || event.time < 0 ? -1 : event.time;
    }

    /**
     * @description 初始化事件提交时间
     */
    chushihua_shijian_tijiao_shijian() {
        if (ailin_sdk_manager.instance.jianchaZaixianShujuShifouKaiqi) {
            const eventSubmitTimeStatus = ailin_sdk_manager.instance.jianchaZaixianShujuShifouKaiqi("event_submit_times");
            console.log("大厅埋点接口请求状态:" + eventSubmitTimeStatus);

            switch (eventSubmitTimeStatus) {
                case $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.ZERO:
                    this.event_submit_times = 60;
                    break;
                case $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.ONE:
                    this.event_submit_times = 120;
                    break;
                case $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.TWO:
                    this.event_submit_times = 0;
                    break;
                case $lobbyConfig.AL_Framework_Lobby_Config.EVENT_SUBMIT_TIME_STATUS.THREE:
                    this.event_submit_times = -1;
                    break;
                default:
                    this.event_submit_times = eventSubmitTimeStatus >= 300 ? 300 : eventSubmitTimeStatus < 0 ? 5 : eventSubmitTimeStatus;
                    break;
            }
            console.log("大厅埋点接口请求时间:" + this.event_submit_times);
        }
    }

    /**
     * @description 发送http请求扩展
     * @param {Object} event 事件对象
     * @param {number} [state=$lobbyConfig.AL_Framework_Lobby_Config.BUNDLE_STATE.CLICK] 事件状态
     */
    fasong_http_qingqiu_kuozhan(event, state = $lobbyConfig.AL_Framework_Lobby_Config.BUNDLE_STATE.CLICK) {
        if (!event) return;

        const bundleState = $lobbyConfig.AL_Framework_Lobby_Config.BUNDLE_STATE;
        if (state === bundleState.EXIT) {
            this.is_BuriedPoint = false;
            this.startTime = 0;
            this.msg = null;
            this.huoquLikaishijian(event);
        }

        const payload = {
            bundleId: event.id || event.bundleId,
            type: state === bundleState.COMPENSATE_EXIT ? bundleState.EXIT : state,
            onlineTime: event.time ?? null,
            version: event.version,
            device: window.device,
            createdAt: Date.parse(new Date()),
        };

        if (state === bundleState.START) {
            this.chushihua_bundle_shijian();
            this.is_BuriedPoint = true;
            this.msg = event;
            this.msg.time = 0;
            this.msg.node = null;
        }

        if (this.event_submit_times === 0) {
            // ailin_sdk_manager.instance.setDataForHttpPust($lobbyConfig.AL_Framework_Lobby_Config.httpUrlEvent, JSON.stringify(payload));
        } else if (this.event_submit_times > 0) {
            let localStorageData = localStorage.getItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key);
            let eventQueue = [];

            if (localStorageData) {
                try {
                    eventQueue = JSON.parse(localStorageData);
                } catch (e) {
                    eventQueue = [];
                }
            }
            eventQueue.push(payload);

            // if (!this.submit_time || (Date.parse(new Date()) - this.submit_time) / 1000 >= this.event_submit_times) {
            //     this.submit_time = Date.parse(new Date());
            //     localStorage.removeItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key);
            //     ailin_sdk_manager.instance.setDataForHttpPust($lobbyConfig.AL_Framework_Lobby_Config.httpUrlBatchEvent, JSON.stringify(eventQueue));
            // } else {
            // }
            localStorage.setItem($lobbyConfig.AL_Framework_Lobby_Config.Event_Submit_Times_Key, JSON.stringify(eventQueue));

            // ailin_sdk_manager.addBossTitle(
            //     "数据埋点：" +
            //     event.bundle +
            //     "---id:" +
            //     event.id +
            //     "----" +
            //     this.bundle_state_string[state - 1] +
            //     (state === 2 ? "----time:" + new Date() : state === 3 ? "----游戏时间:" + event.time : "")
            // );
        }
    }
}

// 单例实例
AL_Framework_Lobby_Buried_Point._instance = null;

// 导出LobbyBuriedPoint
exports.AL_Framework_Lobby_Buried_Point = AL_Framework_Lobby_Buried_Point;
